import QtQuick
import QtQuick.Controls

Window {
    visible: true
    width: 400
    height: 600
    title: "SwipeDelegate Demo"

    ListModel {
        id: listModel
        ListElement { name: "Item 1" }
        ListElement { name: "Item 2" }
        ListElement { name: "Item 3" }
    }

    ListView {
        id: listView
        anchors.fill: parent
        model: listModel
        delegate: SwipeDelegate {
            id: swipeDelegate
            text: name
            width: listView.width

            // 在自定义组件中响应点击
            swipe.right: Rectangle {
                width: parent.width
                height: parent.height
                color: "#f0f0f0"

                Label {
                    text: "Click"
                    color: "#333"
                    anchors.centerIn: parent
                }

                MouseArea {
                    anchors.fill: parent
                    onClicked: console.log("clicked : " + name)
                }
            }
        }
    }
}
